package com.bf.tool;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

import com.bf.zk.constants.Constants;

public class DoCue {

	 @SuppressWarnings("unused")
	private String message = null;  
	    private int secends = 0;  
	    private JLabel label = new JLabel();  
	    private JButton confirm;   
	    private JDialog dialog = null;  
	    boolean result = false;  
	    public  boolean DoCue(JFrame father, String message, int sec) {  
	          Constants.cueMessage=message;
	        this.message = message;  
	        secends = sec;  
	        label.setText(Constants.cueMessage);  
	        label.setBounds(80,15,300,20);  
	        ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();  
	        confirm = new JButton("确认");  
	        confirm.setBounds(150,50,80,30);  
	        confirm.addActionListener(new ActionListener() {              
	            @Override  
	            public void actionPerformed(ActionEvent e) {  
	                result = false;  
	                DoCue.this.dialog.dispose();  
	            }  
	        });  
	        dialog = new JDialog(father, true);
	        //dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
	        dialog.setTitle("倒计时 "+secends+" 秒");  
	        dialog.setLayout(null);  
	        dialog.add(label); 
	        dialog.add(confirm);  
	        ses.scheduleAtFixedRate(new Runnable() {  
	              
	            @Override  
	            public void run() {  
	            	DoCue.this.secends--;  
	                if(DoCue.this.secends == 0) {  
	                	DoCue.this.dialog.dispose();  
	                }else {  
	                    dialog.setTitle("倒计时 "+secends+" 秒"); 
	                    //label.setText(Constants.cueMessage+"倒计时 "+secends+" 秒");  
	                }  
	            }  
	        }, 1, 1, TimeUnit.SECONDS);  
	        dialog.pack();  
	        dialog.setSize(new Dimension(400,120));  
	        dialog.setLocationRelativeTo(father);  
	        dialog.setVisible(true);  
	        return result;  
	    }  
	}  
